<?php
namespace app\common\redis;

use Redis;

class Base
{
    private $my = null;

    public static function factory() {
        return new static();
    }

    public function __construct(){
        $redisConfig = config('redis');
        $redis = new Redis();
        $redis->connect($redisConfig['host'], $redisConfig['port']);
        $redis->select($redisConfig['select']);
        $this->my = $redis;
    }

    public function setArray($key, $arr, $time = null) {
        if($time) {
            $this->my->setex($key, $time, serialize($arr));
        } else {
            $this->my->set($key, serialize($arr));
        }
    }

    public function getArray($key) {
        $arr = $this->my->get($key);
        return unserialize($arr);
    }

    public function __call($name, $arguments) {
        return $this->my->$name(...$arguments);
    }

    public static function __callStatic($name, $arguments) {
        return Redis::$name(...$arguments);
    }

}
